package RRD::Fields;

use strict;
use warnings;

our @ISA = 'Exporter';

our %EXPORT_TAGS = (
  all => [qw/
    default_fields
    field_types
  /],
);
our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;


sub default_fields
{
  # these are the things that i think it's worth graphing, by no means are they
  # all that's worth looking at. if you're in the process of developing
  # code/queries or checking out the status of your db that run against a
  # database there's a lot of other things you should look at. things like
  # Sort_merge_passes, Select_scan, query cache stuff, threads created, etc.
  # (if you're using it) etc. etc.
  [qw/
    Aborted_connects
    Bytes_received
    Bytes_sent
    Com_commit
    Com_delete
    Com_insert
    Com_rollback
    Com_select
    Com_update
    Connections
    Created_tmp_disk_tables
    Created_tmp_tables
    Prepared_stmt_count
    Questions
    Slow_queries
    Threads_connected
    /];
}

sub field_types
{
  # see:
  # http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html
  # the whole truncated name thing is annoying as hell
  {
    ## general status
    Aborted_clients                   => 'COUNTER',
    Aborted_connects                  => 'COUNTER',
    Binlog_cache_disk_use             => {
      name => 'Binlog_cache_duse',
      type => 'GAUGE',
    },
    Binlog_cache_use                  => 'GAUGE',
    Bytes_received                    => 'COUNTER',
    Bytes_sent                        => 'COUNTER',
    Com_admin_commands                => 'COUNTER',
    Com_alter_db                      => 'COUNTER',
    Com_alter_table                   => 'COUNTER',
    Com_analyze                       => 'COUNTER',
    Com_backup_table                  => 'COUNTER',
    Com_begin                         => 'COUNTER',
    Com_call_procedure                => 'COUNTER',
    Com_change_db                     => 'COUNTER',
    Com_change_master                 => 'COUNTER',
    Com_check                         => 'COUNTER',
    Com_checksum                      => 'COUNTER',
    Com_commit                        => 'COUNTER',
    Com_create_db                     => 'COUNTER',
    Com_create_function               => 'COUNTER',
    Com_create_index                  => 'COUNTER',
    Com_create_table                  => 'COUNTER',
    Com_create_user                   => 'COUNTER',
    Com_dealloc_sql                   => 'COUNTER',
    Com_delete                        => 'COUNTER',
    Com_delete_multi                  => 'COUNTER',
    Com_do                            => 'COUNTER',
    Com_drop_db                       => 'COUNTER',
    Com_drop_function                 => 'COUNTER',
    Com_drop_index                    => 'COUNTER',
    Com_drop_table                    => 'COUNTER',
    Com_drop_user                     => 'COUNTER',
    Com_execute_sql                   => 'COUNTER',
    Com_flush                         => 'COUNTER',
    Com_grant                         => 'COUNTER',
    Com_ha_close                      => 'COUNTER',
    Com_ha_open                       => 'COUNTER',
    Com_ha_read                       => 'COUNTER',
    Com_help                          => 'COUNTER',
    Com_insert                        => 'COUNTER',
    Com_insert_select                 => 'COUNTER',
    Com_kill                          => 'COUNTER',
    Com_load                          => 'COUNTER',
    Com_load_master_data              => {
      name => 'Com_load_master_dat',
      type => 'COUNTER',
    },
    Com_load_master_table             => {
      name => 'Com_load_master_tbl',
      type => 'COUNTER',
    },
    Com_lock_tables                   => 'COUNTER',
    Com_optimize                      => 'COUNTER',
    Com_preload_keys                  => 'COUNTER',
    Com_prepare_sql                   => 'COUNTER',
    Com_purge                         => 'COUNTER',
    Com_purge_before_date             => {
      name => 'Com_purge_bf_date',
      type => 'COUNTER',
    },
    Com_rename_table                  => 'COUNTER',
    Com_repair                        => 'COUNTER',
    Com_replace                       => 'COUNTER',
    Com_replace_select                => 'COUNTER',
    Com_reset                         => 'COUNTER',
    Com_restore_table                 => 'COUNTER',
    Com_revoke                        => 'COUNTER',
    Com_revoke_all                    => 'COUNTER',
    Com_rollback                      => 'COUNTER',
    Com_savepoint                     => 'COUNTER',
    Com_select                        => 'COUNTER',
    Com_set_option                    => 'COUNTER',
    Com_show_binlog_events            => {
      name => 'Com_show_bl_events',
      type => 'COUNTER',
    },
    Com_show_binlogs                  => 'COUNTER',
    Com_show_charsets                 => 'COUNTER',
    Com_show_collations               => 'COUNTER',
    Com_show_column_types             => {
      name => 'Com_show_column_typ',
      type => 'COUNTER',
    },
    Com_show_create_db                => 'COUNTER',
    Com_show_create_table             => {
      name => 'Com_show_create_tbl',
      type => 'COUNTER',
    },
    Com_show_databases                => 'COUNTER',
    Com_show_errors                   => 'COUNTER',
    Com_show_fields                   => 'COUNTER',
    Com_show_grants                   => 'COUNTER',
    Com_show_innodb_status            => {
      name => 'Com_show_innodb_sta',
      type => 'COUNTER',
    },
    Com_show_keys                     => 'COUNTER',
    Com_show_logs                     => 'COUNTER',
    Com_show_master_status            => {
      name => 'Com_show_master_sta',
      type => 'COUNTER',
    },
    Com_show_ndb_status               => 'COUNTER',
    Com_show_new_master               => 'COUNTER',
    Com_show_open_tables              => {
      name => 'Com_show_open_tbl',
      type => 'COUNTER',
    },
    Com_show_privileges               => 'COUNTER',
    Com_show_processlist              => {
      name => 'Com_show_pl',
      type => 'COUNTER',
    },
    Com_show_slave_hosts              => {
      name => 'Com_show_slave_hs',
      type => 'COUNTER',
    },
    Com_show_slave_status             => {
      name => 'Com_show_slave_st',
      type => 'COUNTER',
    },
    Com_show_status                   => 'COUNTER',
    Com_show_storage_engines          => {
      name => 'Com_show_storage_en',
      type => 'COUNTER',
    },
    Com_show_tables                   => 'COUNTER',
    Com_show_triggers                 => 'COUNTER',
    Com_show_variables                => 'COUNTER',
    Com_show_warnings                 => 'COUNTER',
    Com_slave_start                   => 'COUNTER',
    Com_slave_stop                    => 'COUNTER',
    Com_stmt_close                    => 'COUNTER',
    Com_stmt_execute                  => 'COUNTER',
    Com_stmt_fetch                    => 'COUNTER',
    Com_stmt_prepare                  => 'COUNTER',
    Com_stmt_reset                    => 'COUNTER',
    Com_stmt_send_long_data           => {
      name => 'Com_stmt_send_long',
      type => 'COUNTER',
    },
    Com_truncate                      => 'COUNTER',
    Com_unlock_tables                 => 'COUNTER',
    Com_update                        => 'COUNTER',
    Com_update_multi                  => 'COUNTER',
    Com_xa_commit                     => 'COUNTER',
    Com_xa_end                        => 'COUNTER',
    Com_xa_prepare                    => 'COUNTER',
    Com_xa_recover                    => 'COUNTER',
    Com_xa_rollback                   => 'COUNTER',
    Com_xa_start                      => 'COUNTER',
    Compression                       => 'NONE',
    Connections                       => 'COUNTER',
    Created_tmp_disk_tables           => {
      name => 'Created_tmp_dtbl',
      type => 'COUNTER',
    },
    Created_tmp_files                 => 'COUNTER',
    Created_tmp_tables                => 'COUNTER',
    Delayed_errors                    => 'COUNTER',
    Delayed_insert_threads            => {
      name => 'Delayed_insert_thr',
      type => 'COUNTER',
    },
    Delayed_writes                    => 'COUNTER',
    Flush_commands                    => 'COUNTER',
    Handler_commit                    => 'COUNTER',
    Handler_delete                    => 'COUNTER',
    Handler_discover                  => 'COUNTER',
    Handler_prepare                   => 'COUNTER',
    Handler_read_first                => 'COUNTER',
    Handler_read_key                  => 'COUNTER',
    Handler_read_next                 => 'COUNTER',
    Handler_read_prev                 => 'COUNTER',
    Handler_read_rnd                  => 'COUNTER',
    Handler_read_rnd_next             => {
      name => 'Handler_read_rnd_nt',
      type => 'COUNTER',
    },
    Handler_rollback                  => 'COUNTER',
    Handler_savepoint                 => 'COUNTER',
    Handler_savepoint_rollback        => {
      name => 'Handler_savepnt_rb',
      type => 'COUNTER',
    },
    Handler_update                    => 'COUNTER',
    Handler_write                     => 'COUNTER',
    Innodb_buffer_pool_pages_data     => {
      name => 'Innodb_bpool_pdata',
      type => 'GAUGE',
    },
    Innodb_buffer_pool_pages_dirty    => {
      name => 'Innodb_bpool_pdirty',
      type => 'GAUGE',
    },
    Innodb_buffer_pool_pages_flushed  => {
      name => 'Innodb_bpool_pflush',
      type => 'GAUGE',
    },
    Innodb_buffer_pool_pages_free     => {
      name => 'Innodb_bpool_pfree',
      type => 'GAUGE',
    },
    Innodb_buffer_pool_pages_latched  => {
      name => 'Innodb_bpool_platch',
      type => 'GAUGE',
    },
    Innodb_buffer_pool_pages_misc     => {
      name => 'Innodb_bpool_pmisc',
      type => 'GAUGE',
    },
    Innodb_buffer_pool_pages_total    => {
      name => 'Innodb_bpool_ptotal',
      type => 'GAUGE',
    },
    Innodb_buffer_pool_read_ahead_rnd => {
      name => 'Innodb_bpool_rah_rn',
      type => 'COUNTER',
    },
    Innodb_buffer_pool_read_ahead_seq => {
      name => 'Innodb_bpool_rah_sq',
      type => 'COUNTER',
    },
    Innodb_buffer_pool_read_requests  => {
      name => 'Innodb_bpool_rreq',
      type => 'COUNTER',
    },
    Innodb_buffer_pool_reads          => {
      name => 'Innodb_bpool_reads',
      type => 'COUNTER',
    },
    Innodb_buffer_pool_wait_free      => {
      name => 'Innodb_bpool_wfree',
      type => 'COUNTER',
    },
    Innodb_buffer_pool_write_requests => {
      name => 'Innodb_bpool_wreq',
      type => 'COUNTER',
    },
    Innodb_data_fsyncs                => 'COUNTER',
    Innodb_data_pending_fsyncs        => {
      name => 'Innodb_data_pfsyncs',
      type => 'GAUGE',
    },
    Innodb_data_pending_reads         => {
      name => 'Innodb_data_preads',
      type => 'GAUGE',
    },
    Innodb_data_pending_writes        => {
      name => 'Innodb_data_pwrites',
      type => 'GAUGE',
    },
    Innodb_data_read                  => 'COUNTER',
    Innodb_data_reads                 => 'COUNTER',
    Innodb_data_writes                => 'COUNTER',
    Innodb_data_written               => 'COUNTER',
    Innodb_dblwr_pages_written        => {
      name => 'Innodb_dblwr_pwritn',
      type => 'COUNTER',
    },
    Innodb_dblwr_writes               => 'COUNTER',
    Innodb_log_waits                  => 'COUNTER',
    Innodb_log_write_requests         => {
      name => 'Innodb_log_wreqs',
      type => 'COUNTER',
    },
    Innodb_log_writes                 => 'COUNTER',
    Innodb_os_log_fsyncs              => {
      name => 'Innodb_os_lfsyncs',
      type => 'COUNTER',
    },
    Innodb_os_log_pending_fsyncs      => {
      name => 'Innodb_ol_pfsyncs',
      type => 'GAUGE',
    },
    Innodb_os_log_pending_writes      => {
      name => 'Innodb_ol_pwrites',
      type => 'GAUGE',
    },
    Innodb_os_log_written             => {
      name => 'Innodb_ol_written',
      type => 'COUNTER',
    },
    Innodb_page_size                  => 'NONE',
    Innodb_pages_created              => {
      name => 'Innodb_pcreated',
      type => 'COUNTER',
    },
    Innodb_pages_read                 => 'COUNTER',
    Innodb_pages_written              => {
      name => 'Innodb_pwritten',
      type => 'COUNTER',
    },
    Innodb_row_lock_current_waits     => {
      name => 'Innodb_rl_cwaits',
      type => 'GAUGE',
    },
    Innodb_row_lock_time              => {
      name => 'Innodb_rlock_time',
      type => 'COUNTER',
    },
    Innodb_row_lock_time_avg          => {
      name => 'Innodb_rlock_tavg',
      type => 'GAUGE',
    },
    Innodb_row_lock_time_max          => {
      name => 'Innodb_rl_time_max',
      type => 'GAUGE',
    },
    Innodb_row_lock_waits             => {
      name => 'Innodb_rl_waits',
      type => 'COUNTER',
    },
    Innodb_rows_deleted               => 'COUNTER',
    Innodb_rows_inserted              => {
      name => 'Innodb_rinserted',
      type => 'COUNTER',
    },
    Innodb_rows_read                  => 'COUNTER',
    Innodb_rows_updated               => 'COUNTER',
    Key_blocks_not_flushed            => {
      name => 'Key_blk_not_flushed',
      type => 'GAUGE',
    },
    Key_blocks_unused                 => 'GAUGE',
    Key_blocks_used                   => 'GAUGE',
    Key_read_requests                 => 'COUNTER',
    Key_reads                         => 'COUNTER',
    Key_write_requests                => 'COUNTER',
    Key_writes                        => 'COUNTER',
    Last_query_cost                   => 'NONE',
    Max_used_connections              => {
      name => 'Max_uconnections',
      type => 'GAUGE',
    },
    Ndb_cluster_node_id               => 'NONE',
    Ndb_config_from_host              => {
      name => 'Ndb_cfg_from_host',
      type => 'NONE',
    },
    Ndb_config_from_port              => {
      name => 'Ndb_cfg_from_port',
      type => 'NONE',
    },
    Ndb_number_of_data_nodes          => {
      name => 'Ndb_num_data_nodes',
      type => 'GAUGE',
    },
    Not_flushed_delayed_rows          => {
      name => 'Not_flushed_drows',
      type => 'GAUGE',
    },
    Open_files                        => 'GAUGE',
    Open_streams                      => 'GAUGE',
    Open_tables                       => 'GAUGE',
    Opened_tables                     => 'COUNTER',
    Prepared_stmt_count               => 'GAUGE',
    Qcache_free_blocks                => 'GAUGE',
    Qcache_free_memory                => 'GAUGE',
    Qcache_hits                       => 'COUNTER',
    Qcache_inserts                    => 'COUNTER',
    Qcache_lowmem_prunes              => {
      name => 'Qcache_lmem_prunes',
      type => 'COUNTER',
    },
    Qcache_not_cached                 => 'COUNTER',
    Qcache_queries_in_cache           => {
      name => 'Qcache_q_in_cache',
      type => 'COUNTER',
    },
    Qcache_total_blocks               => 'GAUGE',
    Questions                         => 'COUNTER',
    Rpl_status                        => 'NONE',
    Select_full_join                  => 'COUNTER',
    Select_full_range_join            => {
      name => 'Select_f_range_join',
      type => 'COUNTER',
    },
    Select_range                      => 'COUNTER',
    Select_range_check                => 'COUNTER',
    Select_scan                       => 'COUNTER',
    Slave_open_temp_tables            => {
      name => 'Slave_o_temp_tables',
      type => 'GAUGE',
    },
    Slave_retried_transactions        => {
      name => 'Slave_retried_ts',
      type => 'COUNTER',
    },
    Slave_running                     => 'NONE',
    Slow_launch_threads               => 'COUNTER',
    Slow_queries                      => 'COUNTER',
    Sort_merge_passes                 => 'COUNTER',
    Sort_range                        => 'COUNTER',
    Sort_rows                         => 'COUNTER',
    Sort_scan                         => 'COUNTER',
    Ssl_accept_renegotiates           => {
      name => 'Ssl_accept_reneg',
      type => 'COUNTER',
    },
    Ssl_accepts                       => 'COUNTER',
    Ssl_callback_cache_hits           => {
      name => 'Ssl_callback_chits',
      type => 'COUNTER',
    },
    Ssl_cipher                        => 'NONE',
    Ssl_cipher_list                   => 'NONE',
    Ssl_client_connects               => 'COUNTER',
    Ssl_connect_renegotiates          => {
      name => 'Ssl_connect_reneg',
      type => 'COUNTER',
    },
    Ssl_ctx_verify_depth              => {
      name => 'Ssl_ctx_ver_depth',
      type => 'NONE',
    },
    Ssl_ctx_verify_mode               => 'NONE',
    Ssl_default_timeout               => 'NONE',
    Ssl_finished_accepts              => {
      name => 'Ssl_finished_acc',
      type => 'COUNTER',
    },
    Ssl_finished_connects             => {
      name => 'Ssl_finished_conn',
      type => 'COUNTER',
    },
    Ssl_session_cache_hits            => {
      name => 'Ssl_session_chits',
      type => 'COUNTER',
    },
    Ssl_session_cache_misses          => {
      name => 'Ssl_session_cmisses',
      type => 'COUNTER',
    },
    Ssl_session_cache_mode            => {
      name => 'Ssl_session_cmode',
      type => 'NONE',
    },
    Ssl_session_cache_overflows       => {
      name => 'Ssl_session_coverfl',
      type => 'COUNTER',
    },
    Ssl_session_cache_size            => {
      name => 'Ssl_session_csize',
      type => 'GAUGE',
    },
    Ssl_session_cache_timeouts        => {
      name => 'Ssl_session_ctouts',
      type => 'COUNTER',
    },
    Ssl_sessions_reused               => 'COUNTER',
    Ssl_used_session_cache_entries    => {
      name => 'Ssl_used_sess_centr',
      type => 'GAUGE',
    },
    Ssl_verify_depth                  => 'NONE',
    Ssl_verify_mode                   => 'NONE',
    Ssl_version                       => 'NONE',
    Table_locks_immediate             => {
      name => 'Table_locks_immed',
      type => 'COUNTER',
    },
    Table_locks_waited                => 'COUNTER',
    Tc_log_max_pages_used             => {
      name => 'Tc_log_max_pused',
      type => 'GAUGE',
    },
    Tc_log_page_size                  => 'NONE',
    Tc_log_page_waits                 => 'COUNTER',
    Threads_cached                    => 'COUNTER',
    Threads_connected                 => 'GAUGE',
    Threads_created                   => 'COUNTER',
    Threads_running                   => 'GAUGE',
    Uptime                            => 'COUNTER',
    Uptime_since_flush_status         => {
      name => 'Uptime_sin_fstatus',
      type => 'COUNTER',
    },
    ## replication
    Master_log => 'COUNTER',
    Master_position => 'COUNTER',
    Slave_read_log => 'COUNTER',
    Slave_read_position => {
      name => 'Slave_read_pos',
      type => 'COUNTER',
    },
    Slave_exec_log => 'COUNTER',
    Slave_exec_position => {
      name => 'Slave_exec_pos',
      type => 'COUNTER',
    },
    # warning this one is kind of funky/fuzzy
    Slave_seconds_behind => 
    {
      name => 'Slave_sec_behind',
      type => 'GAUGE',
    },
    Slave_read_behind => 'GAUGE',
    Slave_exec_behind_read => 
    {
      name => 'Slave_exec_beh_red',
      type => 'GAUGE',
    },
    Slave_exec_behind_master => {
      name => 'Slave_exec_beh_mst',
      type => 'GAUGE',
    },
    # next two are set up as gauge, but they're really just bool, 0 and 1
    Slave_io_running => 'GAUGE',
    Slave_sql_running => 'GAUGE',
  };
}

1;
